//twopts.txt - Like basic monst, but this character spends all its time oscillating 
// between two nav points.
// Memory Cells:
//   Cell 0 - Dialogue node
//   Cell 1,2 - Stuff done flag. If both 0, nothing. Otherwise when this is killed, set to 1.
//	 Cell 3 - The nav point the character marches to.
//   Cell 4 - If 1, this creature goes straight to the nav point immediately
//     and never returns

begincreaturescript;

variables;

short i,target;
short path_a_or_b = 0;
short last_abil;

body;

beginstate INIT_STATE;
	set_act_at_dist(ME,1);
	if (my_number() != 64)
		set_name(ME,"Servile Spy");
	set_level(ME,30);
	set_boss_level(ME,2);
	set_new_abil(ME,20);
	set_attack_bonus(ME,12);
	bless_char(ME,2);
	force_char_status(ME,18,1);
	force_char_status(ME,16,1);
	
	last_abil = get_current_tick();
	break;

beginstate DEAD_STATE;
	if (my_number() == 64)
		begin_talk_mode(85);
break;

beginstate START_STATE; 
	// if I have a target for some reason, go attack it
	if (target_ok()) {
		if (dist_to_char(get_target()) <= 16)
			set_state(3);
			else set_foe_target(ME,-1);
		}
	
	if (get_foe_target(ME,8,0)) {
		do_attack();
		set_state(3);
		}
	if (who_shot_me() >= 0) {
		set_foe_target(ME,who_shot_me());
		do_attack();
		set_state(3);
		}
	
	if (get_attitude(ME) == 4)
		path_a_or_b = 1;
	if ((path_a_or_b == 0) && (num_chars_in_group(7) == 0) && (gf(78,7) > 0)) {
		path_a_or_b = 1;
		if (my_number() == 64)
			begin_talk_mode(86);
		}
		
	if (path_a_or_b > 0) {
		if (dist_to_nav_point(ME,3) <= 2)
			erase_char(ME);
		approach_nav_point(ME,3,1);
		}

	if (am_i_doing_action() == FALSE)
		end_combat_turn();
break;

beginstate 3; // attacking
	if (target_ok() == FALSE)
		set_state(START_STATE);


	if ((get_nearest_party_char(9) >= 0) && (is_combat())) {
		if ((get_ran(1,0,100) < 50) && (tick_difference(last_abil,get_current_tick()) > 0)) {
			print_named_str(ME,"uses a wand. It fires a beam of energy.");
			pc_heard_sound_delay(131,250);						
		  	place_particle_num(ME,1,1,8);
			run_char_animation(2,1,35);	
			damage_char(get_target(),get_ran(get_level(ME) + get_attack_bonus(ME),1,10),1);
			
			if (get_ran(1,0,100) < 50) {// slow
				shoot_projectile(ME,get_target(),34);
				set_char_status(get_target(),1,-8);
			  	place_particle_num(get_target(),2,6,8);
				}
				else { // curse
					shoot_projectile(ME,get_target(),38);
					set_char_status(get_target(),0,-8);
					set_char_status(get_target(),8,-8);
				  	place_particle_num(get_target(),3,6,8);
					}

			last_abil = get_current_tick();
			end();
			}
		}
	


	do_attack();
break;

beginstate TALKING_STATE;
		print_str("Talking: The servile has nothing to say right now.");

	break;